﻿using System;
using System.Data;

using Wicresoft.Common;

namespace Wicresoft.JDPostBoard.Entity
{
    [Table("Post", "", "JDPB.ConnectionString")]
    public class Post : Info
    {
        #region SQL column name consts
        public const string SQLCOL_ID = "ID";
        public const string SQLCOL_POSTTITLE = "PostTitle";
        public const string SQLCOL_POSTCONTENT = "PostContent";
        public const string SQLCOL_POSTTIME = "PostTime";
        public const string SQLCOL_POSTERID = "PosterID";
        public const string SQLCOL_POSTERNAME = "PosterName";
        public const string SQLCOL_POSTERDSNAME = "PosterDsName";
        public const string SQLCOL_LINKADDRESS = "LinkAddress";
        public const string SQLCOL_ISREAD = "IsRead";
        public const string SQLCOL_ISREPLAY = "IsReplay";
        public const string SQLCOL_ISDELETE = "IsDelete";
        #endregion


        #region Contructors
        /// <summary>
        /// Construct empty entity
        /// </summary>
        public Post() { }

        /// <summary>
        /// Construct entity by primary key, other fields will be assigned by 
        /// "Load" method.
        /// </summary>
        public Post(Guid ID)
        {
            this.ID = ID;
        }
        #endregion

        public override void Init(DataRow row)
        {
            ID = (Guid)ObjectType.GuidTypeHelper.Read(row[SQLCOL_ID]);
            PostTitle = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_POSTTITLE]);
            PostContent = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_POSTCONTENT]);
            PostTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_POSTTIME]);
            PosterID = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_POSTERID]);
            PosterName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_POSTERNAME]);
            PosterDsName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_POSTERDSNAME]);
            LinkAddress = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_LINKADDRESS]);
            IsRead = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISREAD]);
            IsReplay = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISREPLAY]);
            IsDelete = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISDELETE]);
        }

        #region Properties
        #region Property <Guid> ID
        [Property("ID", 16, SqlDbType.UniqueIdentifier, false, true)]
        public Guid ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        private Guid _ID = Guid.Empty;
        #endregion

        #region Property <string> PostTitle
        [Property("PostTitle", 100, SqlDbType.NVarChar, false, false)]
        public string PostTitle
        {
            get { return _PostTitle; }
            set { _PostTitle = value; }
        }
        private string _PostTitle = null;
        #endregion

        #region Property <string> PostContent
        [Property("PostContent", 4000, SqlDbType.NVarChar, false, false)]
        public string PostContent
        {
            get { return _PostContent; }
            set { _PostContent = value; }
        }
        private string _PostContent = null;
        #endregion

        #region Property <DateTime> PostTime
        [Property("PostTime", 16, SqlDbType.DateTime, false, false)]
        public DateTime PostTime
        {
            get { return _PostTime; }
            set { _PostTime = value; }
        }
        private DateTime _PostTime = DateTime.MinValue;
        #endregion

        #region Property <string> PosterID
        [Property("PosterID", 100, SqlDbType.NVarChar, false, false)]
        public string PosterID
        {
            get { return _PosterID; }
            set { _PosterID = value; }
        }
        private string _PosterID = null;
        #endregion

        #region Property <string> PosterName
        [Property("PosterName", 100, SqlDbType.NVarChar, false, false)]
        public string PosterName
        {
            get { return _PosterName; }
            set { _PosterName = value; }
        }
        private string _PosterName = null;
        #endregion

        #region Property <string> PosterDsName
        [Property("PosterDsName", 100, SqlDbType.NVarChar, false, false)]
        public string PosterDsName
        {
            get { return _PosterDsName; }
            set { _PosterDsName = value; }
        }
        private string _PosterDsName = null;
        #endregion

        #region Property <string> LinkAddress
        [Property("LinkAddress", 200, SqlDbType.NVarChar, false, false)]
        public string LinkAddress
        {
            get { return _LinkAddress; }
            set { _LinkAddress = value; }
        }
        private string _LinkAddress = null;
        #endregion

        #region Property <bool> IsRead
        [Property("IsRead", 1, SqlDbType.Bit, false, false)]
        public bool IsRead
        {
            get { return _IsRead; }
            set { _IsRead = value; }
        }
        private bool _IsRead = false;
        #endregion

        #region Property <bool> IsReplay
        [Property("IsReplay", 1, SqlDbType.Bit, false, false)]
        public bool IsReplay
        {
            get { return _IsReplay; }
            set { _IsReplay = value; }
        }
        private bool _IsReplay = false;
        #endregion

        #region Property <bool> IsDelete
        [Property("IsDelete", 1, SqlDbType.Bit, false, false)]
        public bool IsDelete
        {
            get { return _IsDelete; }
            set { _IsDelete = value; }
        }
        private bool _IsDelete = false;
        #endregion
        #endregion




    }
}
